﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Xml;

namespace CNVP.Config
{
    public class SchemeRules
    {
        /// <summary>
        /// 得到配置文件
        /// </summary>
        /// <param name="Item"></param>
        /// <returns></returns>
        public static string GetConfigParamvalue(string Item)
        {
            return string.Empty;
        }
        /// <summary>
        /// 读取配置文件
        /// </summary>
        /// <param name="Target"></param>
        /// <returns></returns>
        public static string GetConfigValue(string Target)
        {
            string path = HttpContext.Current.Server.MapPath("~/Config/SchemeRules.config");
            return GetConfigValue(Target, path);
        }
        /// <summary>
        /// 读取配置文件
        /// </summary>
        /// <param name="Target"></param>
        /// <param name="ConfigPathName"></param>
        /// <returns></returns>
        static internal string GetConfigValue(string Target, string XmlPath)
        {
            System.Xml.XmlDocument xdoc = new XmlDocument();
            xdoc.Load(XmlPath);
            XmlElement root = xdoc.DocumentElement;
            XmlNodeList elemList = root.GetElementsByTagName(Target);
            try
            {
                return elemList[0].InnerText;
            }
            catch
            {
                return null;
            }
        }
        /// <summary>
        /// 保存配置信息
        /// </summary>
        /// <param name="strTarget"></param>
        /// <param name="strValue"></param>
        public static void SaveXmlConfig(string strTarget, string strValue)
        {
            string xmlPath = HttpContext.Current.Server.MapPath("~/Config/SchemeRules.config");
            System.Xml.XmlDocument xdoc = new XmlDocument();
            xdoc.Load(xmlPath);
            XmlElement root = xdoc.DocumentElement;
            XmlNodeList elemList = root.GetElementsByTagName(strTarget);
            elemList[0].InnerXml = strValue;
            xdoc.Save(xmlPath);
        }
        /// <summary>
        /// 刷新缓存
        /// </summary>
        public static string GetCatchParam(string Target)
        {
            string path = System.Web.HttpContext.Current.Server.MapPath("~/Config/SchemeRules.config");
            System.Xml.XmlDocument xdoc = new XmlDocument();
            xdoc.Load(path);
            XmlElement root = xdoc.DocumentElement;
            XmlNodeList elemList = root.GetElementsByTagName(Target);
            try
            {
                return elemList[0].InnerText;
            }
            catch
            {
                return null;
            }
        }

        public static string srAdd = GetConfigValue("Add");
        public static string srEdit = GetConfigValue("Edit");
        public static string srDay = GetConfigValue("Day");
        public static string srNight = GetConfigValue("Night");
        /// <summary>
        /// 刷新缓存
        /// </summary>
        public static void RefurbishCatch()
        {
            srAdd = GetConfigValue("Add");
            srEdit = GetConfigValue("Edit");
            srDay = GetConfigValue("Day");
            srNight = GetConfigValue("Night");
        }
    }
}
